package com.cosina.game.crystallight.model.crystal;

import com.cosina.game.crystallight.MediaPlayerAdapter;
import com.cosina.game.crystallight.engine.BattleEngine;

public class UpgradeSystem {
	
	public final int MAX_LEVEL = 24;
	
	static int[] abilityLevelLimit = {0,3,6,12,24};
	static int[] maneRequired = {0,100,200,300,400};
	public static int getMaxLevel(int crystalLevel){
		return abilityLevelLimit[crystalLevel];
	}
	
	public static boolean canSpeedUpdate(Crystal crystal){
		if(getMaxLevel(crystal.level) > crystal.speedLevel){
			return BattleEngine.manaFlask.getCurrent() >= maneRequired[crystal.level];
		}
		return false;
	}
	
	public static boolean canRangeUpdate(Crystal crystal){
		if(getMaxLevel(crystal.level) > crystal.rangeLevel){
			return BattleEngine.manaFlask.getCurrent() >= maneRequired[crystal.level];
		}
		return false;
	}
	
	
	public static void upgradeSpeed(Crystal crystal){
		if(getMaxLevel(crystal.level) <= crystal.speedLevel){
			throw new IllegalStateException("this upgrade level is current max");
		}
		MediaPlayerAdapter.upgrade();
		BattleEngine.manaFlask.used(maneRequired[crystal.level]);
		crystal.speedLevel ++;
		crystal.weapon.speedPercent = crystal.speedLevel / (getMaxLevel(crystal.level) + 0f);
		crystal.weapon.attackCount.setMax(DEFAULT_SPEED - crystal.speedLevel/2);
	}
	
	public static void upgradeRange(Crystal crystal){
		if(getMaxLevel(crystal.level) <= crystal.rangeLevel){
			throw new IllegalStateException("this upgrade level is current max");
		}
		MediaPlayerAdapter.upgrade();
		BattleEngine.manaFlask.used(maneRequired[crystal.level]);
		crystal.rangeLevel ++;
		crystal.weapon.rangePercent = crystal.rangeLevel / (getMaxLevel(crystal.level) + 0f);
		crystal.weapon.range = DEFAULT_RANGE + crystal.rangeLevel*3;
	}
	public static final int DEFAULT_SPEED = 15;
	public static final int DEFAULT_RANGE = 75;
	
}
